package P819.V2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Problema da disciplina de Estrutura de Dados e Complexidade de Algoritmos da
 * Pos Graduacao do Periodo 2011.1
 *
 * @see http://br.spoj.pl/problems/PEDAGIO/
 * @author Elenilson Vieira - 111100371 - elenilson[at]elenilsonvieira.com
 * @since 12 de junho de 2011
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String line = null;
        int testNumber = 1;
        StringBuilder result = new StringBuilder();

        while (!(line = reader.readLine().trim()).equals("0 0 0 0")) {
            String data[] = line.split(" ");
            int citiesAmount = Integer.parseInt(data[0]);
            int roadsAmount = Integer.parseInt(data[1]);
            String jucaCityString = data[2];
            int jucaCityInt = Integer.parseInt(jucaCityString);
            int maxToll = Integer.parseInt(data[3]);
            StringBuilder cities = new StringBuilder();
            boolean citiesToVisit[] = new boolean[citiesAmount+ 1];

            Map<String, Set<String>> graph = new HashMap<String, Set<String>>();

            for (int i= 0; i < roadsAmount; i++) {
                line = reader.readLine();
                data = line.split(" ");
                String x = data[0];
                String y = data[1];

                /*** Adiciona a estrada de x para y ***/
                Set<String> set = graph.get(x);
                if(set == null){
                    set = new HashSet<String>();
                    graph.put(x, set);
                }

                set.add(y);

                /*** Adiciona a estrada de y para x ***/
                set = graph.get(y);
                if(set == null){
                    set = new HashSet<String>();
                    graph.put(y, set);
                }

                set.add(x);
            }

            Set<Set<String>> levelCitiesRoad = new HashSet<Set<String>>();
            levelCitiesRoad.add(graph.get(jucaCityString));

            for (int i= 0; i < maxToll; i++) {
                Set<Set<String>> nextLevelCities = new HashSet<Set<String>>();

                for (Set<String> levelCitieRoad : levelCitiesRoad) {
                    if(levelCitieRoad != null){
                        for (String roadTo : levelCitieRoad) {
                            int roadToInt = Integer.parseInt(roadTo);
                            if(!citiesToVisit[roadToInt] && !roadTo.equals(jucaCityString)){
                                nextLevelCities.add(graph.get(roadTo));
                                citiesToVisit[roadToInt] = true;
                            }
                        }
                    }
                }

                levelCitiesRoad = nextLevelCities;
            }

            for (int i= 1; i < citiesToVisit.length; i++) {
                if(citiesToVisit[i]){
                    cities.append(i).append(" ");
                }
            }

            result.append(String.format("Teste %d\n%s\n\n", testNumber++, cities.toString().trim()));
        }

        System.out.print(result.toString());
    }
}
